package org.light.framework.orm;

import org.light.framework.enumeration.IEnum;
import org.light.framework.util.EnumUtil;
import org.light.framework.util.StringUtil;

/**
 * Jdbc值与java值转换器
 * 
 * @author de.cel
 *
 */
public class DbValueConverter {

	/**
	 * jdbc类型转java类型
	 * @param clazz
	 * @param value
	 * @return
	 */
	public static Object jdbc2Java(Class<?> clazz, Object value) {
		return StringUtil.convert(value, clazz);
	}

	/**
	 * java类型转jdbc类型
	 * @param value
	 * @return
	 */
	public static Object java2Jdbc(Object value) {

		if (value instanceof IEnum) {
			value = EnumUtil.getId(value);
		} else if (value instanceof Boolean) {
			value = (boolean) value ? 1 : 0;
		}

		return value;
	}

}
